package com.erp.erp_ui.CarryPlan;

import com.erp.erp_entitys.CarryPlan.CarryPlan;
import com.erp.erp_entitys.CarryPlan.CarryPlanProduct;
import com.erp.erp_servers.CarryPlan.CarryPlanProductService;
import com.erp.utils.R;
import com.erp.utils.ResultStatusEnum;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 出运计划产品明细表(CarryPlanProduct)表控制层
 *
 * @author makejava
 * @since 2020-10-15 23:30:14
 */
@RestController
@RequestMapping("carryPlanProduct")
public class CarryPlanProductController {
    /**
     * 服务对象
     */
    @Resource
    private CarryPlanProductService carryPlanProductService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public CarryPlanProduct selectOne(Integer id) {
        return this.carryPlanProductService.queryById(id);
    }

    /**
     * 出运计划新增
     * @param carryPlanProduct
     * @return
     */
    @RequestMapping(value = "save",method = RequestMethod.POST)
    @ResponseBody
    public Object saveCarryPlan(@RequestBody CarryPlanProduct carryPlanProduct){
        try{
            if(carryPlanProduct.getId()!=null){
                return R.build(this.carryPlanProductService.update(carryPlanProduct));
            }else{
                return R.build(this.carryPlanProductService.insert(carryPlanProduct));
            }
        }catch (Exception e){
            e.printStackTrace();
            return R.buildError(ResultStatusEnum.ERROR);
        }

    }

    @RequestMapping(value = "select")
    @ResponseBody
    public Object selectCarryPlan(int parentid,int page,int limit){
        try{

            PageInfo<CarryPlanProduct> pageInfoList = this.carryPlanProductService.pageSelect(parentid,page,limit);
            return R.build(200, "success", pageInfoList.getTotal(), pageInfoList.getList());
        }catch (Exception e){
            e.printStackTrace();
            return R.buildError(ResultStatusEnum.ERROR);
        }

    }


}